package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.CourseDetails;
import com.example.fitnessservice.module.pojo.CourseDetailsCamp;
import com.example.fitnessservice.module.pojo.Result;
import com.example.fitnessservice.service.CourseService;
import com.example.fitnessservice.service.EnterForCampService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author feng
 * @version 1.0
 * @&#064;description: TODO
 * @&#064;date 2022/11/24 11:48
 */
@RestController
@RequestMapping("/course")
public class FindCourseController {
    @Resource
    CourseService courseService;

    /*查询某个状态场馆
    所以的课程
     */
    @GetMapping("place/{placeId}/{type}/{currentPage}/{pageSize}")
    public Result findOnePlaceCourse(
            @PathVariable Integer placeId,
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @PathVariable Integer type
    ) {
        Result result = new Result();
        PageHelper.startPage(currentPage, pageSize);
        List<CourseDetails> details = courseService.findOnePlaceCourse(placeId, type);
        if (!CollectionUtils.isEmpty(details)) {
            PageInfo<CourseDetails> pageInfo = new PageInfo<>(details);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }
    /*
    查询某个场馆非训练营课程
     */

    @GetMapping("course/{courseType}/{type}/{x}/{y}/{currentPage}/{pageSize}")
    public Result findTeamCourse(
            @PathVariable Integer courseType,
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @PathVariable Integer type,
            @PathVariable Integer x,
            @PathVariable Integer y
    ) {
        Result result = new Result();
        PageHelper.startPage(currentPage, pageSize);
        List<CourseDetails> details = courseService.findNormalCourse(courseType, type,x,y);
        if (!CollectionUtils.isEmpty(details)) {
            PageInfo<CourseDetails> pageInfo = new PageInfo<>(details);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }
    /*
    查询联合团课，联合场地进行排序，type为进行中/已结束/未开始
     */
    @Resource
    EnterForCampService enterForCampService;
    @GetMapping("camp/{type}/{x}/{y}/{currentPage}/{pageSize}")
    public Result findCampCourse(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @PathVariable Integer type,
            @PathVariable Integer x,
            @PathVariable Integer y
    ) {
        enterForCampService.updateCourseStatus(new Date());
        Result result = new Result();
        PageHelper.startPage(currentPage, pageSize);
        List<CourseDetailsCamp> details = courseService.findCampCourse(type,x,y);
        if (!CollectionUtils.isEmpty(details)) {
            PageInfo<CourseDetailsCamp> pageInfo = new PageInfo<>(details);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }
}
